//
//  Pet_AddRecordViewController.swift
//  PetApp
//
//  Created by mac on 2023/9/20.
//  Copyright © 2023 Pet_. All rights reserved.
//

import UIKit

class Pet_AddRecordViewController: BasicViewController {

    private var nameL = UILabel.initV(.setTypeFace(22.Fit,type: .bold), text: "Please select the type of thing to record", textColor:.black)
    let nameArr = ["Health","Food","Clean","Others"]
    let imgArr = ["icon_Health","icon_Food","icon_Clean","icon_Others"]
    
    private lazy var recordView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.minimumLineSpacing = 10.Fit
        layout.minimumInteritemSpacing = 10.Fit
        layout.scrollDirection = .vertical
        layout.itemSize = .init(width: 150.Fit, height: 200.Fit)
        let view = UICollectionView(frame: .zero, collectionViewLayout: layout)
        view.register(Record_Item.self, forCellWithReuseIdentifier: Record_Item.description())
        view.contentInset = .init(top: 0, left: 30.Fit, bottom: 0, right: 30.Fit)
        view.backgroundColor = .clear
        view.delegate = self
        view.dataSource = self
        view.bounces = false
        return view
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.subviews {
            nameL
            recordView
        }
        nameL.left(15.Fit).right(15.Fit).top(NavHeight + 50.Fit)
        nameL.centerHorizontally()
        nameL.textAlignment = .center
        recordView.left(0).right(0).bottom(0)
        recordView.Top == nameL.Bottom + 35.Fit
    }
    
}
    
    
extension Pet_AddRecordViewController:UICollectionViewDelegate,UICollectionViewDataSource{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return nameArr.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let item = collectionView.dequeueReusableCell(withReuseIdentifier: Record_Item.description(), for: indexPath) as! Record_Item
        item.coverI.image = .init(named: imgArr[indexPath.item])
        item.namel.text = nameArr[indexPath.item]
        return item
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let view1 = Record_View()
        view1.typeimg.image = .init(named: imgArr[indexPath.item])
        view1.typeLabel.text = nameArr[indexPath.item]
        view1.recordBlock = {
            self.navigationController?.popViewController(animated: true)
        }
        let page = Pop_Up_Custom_View(config: PopUpViewConfig(view: view1, size: CGSize(width: screenWidth-30.Fit, height: 445.Fit)))
        page.isCloseFromClean = false
        page.animatedPop()
    }
    
}

class Record_Item: UICollectionViewCell {
    
    let coverI = UIImageView.initImgView(img: "")
    let namel = UILabel.initV(.setTypeFace(16.Fit), text: "", textColor: .black)
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.subviews {
            coverI
            namel
        }
        coverI.size(80.Fit).top(0)
        coverI.centerHorizontally()
        
        namel.left(0).right(0).height(25.Fit)
        namel.textAlignment = .center
        namel.Top == coverI.Bottom + 15.Fit
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
